package com.gitee.ly.filter;

import lombok.extern.slf4j.Slf4j;
import org.noear.solon.annotation.Component;
import org.noear.solon.annotation.Inject;
import org.noear.solon.core.handle.Context;
import org.noear.solon.core.handle.Filter;
import org.noear.solon.core.handle.FilterChain;

import java.util.Objects;

@Slf4j
@Component(index = 0)
public class AuthFilter implements Filter {
    @Inject("${auth.u}")
    private String u;

    @Override
    public void doFilter(Context ctx, FilterChain chain) throws Throwable {
        String headerU = ctx.header("u");
        if (!Objects.equals(headerU, u)) {
            log.error("header u={} error", headerU);
            ctx.status(500);
        } else {
            chain.doFilter(ctx);
        }
    }
}
